<template>
  <avue-chat ref="chat" :keylist="keylist"
             @keysend="handleSubmit"
             @keyadd="handleAdd"
             :config="config"
             width="420"
             height="560"
             @submit="handleSubmit"
             v-model="msg"
             :list="list">
  </avue-chat>
</template>
<script>
import {EventBus, EventBusType} from "@/utils/event-bus";

export default {
  name: "p2p-chat-message",
  data() {
    return {
      config: {
        img: '',
        name: '聊天窗口',
        dept: ''
      },
      // 快捷发送（发送按钮，下拉显示）
      keylist: [],
      msg: '这是你想说的话～。～',
      list: []
    }
  },
  created() {
    console.log("load p2p chat message end;")
    // 先$off注销事件，否避免导致多次监听问题
    EventBus.$off(EventBusType.P2P_CHAT);
    EventBus.$on(EventBusType.P2P_CHAT, mn => {
      this.handleReceive(mn);
    });
  },
  mounted() {

  },
  methods: {
    // 添加快捷回复
    handleAdd(msg) {
      this.keylist.push(msg);
    },
    // 发送信息
    handleSubmit(msg) {
      this.msg = msg || this.msg
      this.$refs.chat.pushMsg({
        mine: true,
        text: this.msg
      });
      this.msg = '';
    },

    // 接收消息
    handleReceive(msg) {
      console.log("p2p chat message", msg)
    }
  }
}
</script>
<style>
</style>
